package com.whfc.wxmp.api.mach.v1.controller;

import com.whfc.common.result.ListData;
import com.whfc.common.result.PageData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.DateUtil;
import com.whfc.wxmp.annotation.CurrentWxUser;
import com.whfc.fuum.entity.WxUser;
import com.whfc.mach.dto.AppMachDataStatDTO;
import com.whfc.mach.dto.MachDayDataDTO;
import com.whfc.mach.dto.report.AppMachReportDTO;
import com.whfc.wxmp.api.mach.v1.service.WxmpMachReportService;
import com.whfc.wxmp.util.RequestConetxtUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author sun_guodong
 * @description 小程序设备报表
 * @date 2020-12-14
 */
@RestController
@RequestMapping("/mp/api/v1/mach/report")
public class WxmpMachReportController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxmpMachReportService wxmpMachReportService;

    @GetMapping("/dayReport/list")
    public Result dayReportDataList(@CurrentWxUser WxUser user,
                                    @RequestParam("deptId") Integer deptId,
                                    @RequestParam("pageNum") Integer pageNum,
                                    @RequestParam("pageSize") Integer pageSize) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取设备日报列表", RequestConetxtUtil.getParameters());
        PageData<AppMachReportDTO> pageData = wxmpMachReportService.dayReportDataList(deptId, pageNum, pageSize);
        return ResultUtil.success(pageData);
    }

    @GetMapping("/weekReport/list")
    public Result weekReportDataList(@CurrentWxUser WxUser user,
                                     @RequestParam("deptId") Integer deptId,
                                     @RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取设备周报列表", RequestConetxtUtil.getParameters());
        PageData<AppMachReportDTO> pageData = wxmpMachReportService.getWeekReportDataList(deptId, pageNum, pageSize);
        return ResultUtil.success(pageData);
    }

    @GetMapping("/monthReport/list")
    public Result monthReportDataList(@CurrentWxUser WxUser user,
                                      @RequestParam("deptId") Integer deptId,
                                      @RequestParam("pageNum") Integer pageNum,
                                      @RequestParam("pageSize") Integer pageSize) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取设备月报列表", RequestConetxtUtil.getParameters());
        PageData<AppMachReportDTO> pageData = wxmpMachReportService.getMonthReportDataList(deptId, pageNum, pageSize);
        return ResultUtil.success(pageData);
    }

    @GetMapping("/dayReport/data/stat")
    public Result dayReportStat(@CurrentWxUser WxUser user,
                                @RequestParam("deptId") Integer deptId,
                                @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam("date") Date date) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取设备日报统计数据", RequestConetxtUtil.getParameters());
        AppMachDataStatDTO data = wxmpMachReportService.dayReportStat(deptId, date);
        return ResultUtil.success(data);
    }

    @GetMapping("/weekReport/data/stat")
    public Result weekReportStat(@CurrentWxUser WxUser user,
                                 @RequestParam("deptId") Integer deptId,
                                 @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam("startDate") Date startDate,
                                 @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam("endDate") Date endDate) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取设备周报统计数据", RequestConetxtUtil.getParameters());
        AppMachDataStatDTO data = wxmpMachReportService.weekReportStat(deptId, startDate, endDate);
        return ResultUtil.success(data);
    }

    @GetMapping("/monthReport/data/stat")
    public Result monthReportStat(@CurrentWxUser WxUser user,
                                  @RequestParam("deptId") Integer deptId,
                                  @DateTimeFormat(pattern = "yyyy-MM") @RequestParam("month") Date month) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取设备月报统计数据", RequestConetxtUtil.getParameters());
        Date startDate = DateUtil.getMonthBegin(month);
        Date endDate = DateUtil.getMonthEnd(month);
        AppMachDataStatDTO data = wxmpMachReportService.weekReportStat(deptId, startDate, endDate);
        return ResultUtil.success(data);
    }

    @GetMapping("/dayReport/data")
    public Result dayReport(@CurrentWxUser WxUser user,
                            @RequestParam("deptId") Integer deptId,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam("date") Date date) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取设备日报", RequestConetxtUtil.getParameters());
        ListData<MachDayDataDTO> listData = wxmpMachReportService.dayReport(deptId, date);
        return ResultUtil.success(listData);
    }

    @GetMapping("/weekReport/data")
    public Result weekReport(@CurrentWxUser WxUser user,
                             @RequestParam("deptId") Integer deptId,
                             @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam("startDate") Date startDate,
                             @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam("endDate") Date endDate) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取设备周报", RequestConetxtUtil.getParameters());
        ListData<MachDayDataDTO> listData = wxmpMachReportService.weekReport(deptId, startDate, endDate);
        return ResultUtil.success(listData);
    }

    @GetMapping("/monthReport/data")
    public Result monthReport(@CurrentWxUser WxUser user,
                              @RequestParam("deptId") Integer deptId,
                              @DateTimeFormat(pattern = "yyyy-MM") @RequestParam("month") Date month) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取设备月报", RequestConetxtUtil.getParameters());
        Date startDate = DateUtil.getMonthBegin(month);
        Date endDate = DateUtil.getMonthEnd(month);
        ListData<MachDayDataDTO> listData = wxmpMachReportService.weekReport(deptId, startDate, endDate);
        return ResultUtil.success(listData);
    }
}
